package com.hmall.item.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.common.dto.PageDTO;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.TbItemService;
import com.hmall.item.mapper.TbItemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author lijian
* @description 针对表【tb_item(商品表)】的数据库操作Service实现
* @createDate 2022-07-20 16:46:09
*/
@Service("TbItemService")
public class TbItemServiceImpl extends ServiceImpl<TbItemMapper, Item>
    implements TbItemService{

    @Autowired
    private TbItemMapper tbItemMapper;

    @Override
    public PageDTO<Item> searchItemByPage(Long page, Long size) {
        Page<Item> itemPage = new Page<>(page, size);
        Page<Item> resultPage = tbItemMapper.selectPage(itemPage, null);
        List<Item> records = resultPage.getRecords();
        long total = resultPage.getTotal();
        PageDTO<Item> result = PageDTO.<Item>builder().total(total).list(records).build();
        return result;
    }

    @Override
    public void updateStatusById(Long id, Integer status) {
        int result = tbItemMapper.updateStatusById(id,status);
    }
}




